﻿using System.Collections.Generic;
using System.IO;
using CYZHAPI.Entity;
using CYZHAPI.IRepository;
using CYZHAPI.IRepository.IService;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;


namespace CYZHAPI.Repository.Service
{
    public class RolService : IRolService
    {
        private IRolRep _rolRep;

        public RolService(IRolRep rolRep)
        {
            _rolRep = rolRep;
        }
        
        public jsonRolModel get(string Userid, string pRolid)
        {
            string path = Directory.GetCurrentDirectory();
            /*IConfiguration  config = new ConfigurationBuilder()
                //.Add(JsonConfigurationProvider("viewconfig/index.json"))
                //.SetBasePath(Directory.GetCurrentDirectory()) // 这里添加配置文件 
                .AddJsonFile(path+@"\viewconfig\index.json", true) 
                .Build();//, IConfigurationRoot config
            IEnumerable<IConfigurationSection> s =config.GetSection("indexModes").GetChildren();
            foreach (IConfigurationSection v in s)
            {
                 //string nn = v.GetValue(v.Key);
            }
            IConfigurationSection objConfig = config.GetSection("indexModes");*/

            List<RolModel> objRol = _rolRep.get(Userid,pRolid);
            jsonRolModel objjson = new jsonRolModel();
            if (objRol != null && objRol.Count > 0)
            {
                objjson.code = "200";
                objjson.reMessage = objRol;
            }
            else
            {
                objjson.code = "402";
                objjson.reMessage = null;
            }
            return objjson;
        }
    }
}